
## 'appendix.do' generates the 'temp-R.dta' file
## setwd to whichever is the working directory that contains this replication arhive

library(FindIt)
library(foreign)

lapop <- read.dta("replication/temp-R.dta", 
                  convert.factors=TRUE)
lapop$bribe <- factor(lapop$bribe, ordered = TRUE, levels=c("BribesJobs","BribesCommon","Bribes","NoBribes"))
lapop$copartisan <- factor(lapop$copartisan,ordered=FALSE,levels=c("CopCand","OutCand"))
lapop$copsource <- factor(lapop$copsource,ordered=FALSE,levels=c("Court","OutNews","CopNews"))
lapop$female <- factor(lapop$female,ordered=FALSE,levels=c("Male","Female"))

# ANOVA model run
fit <- CausalANOVA(formula=vote ~ bribe + copartisan + copsource + female,
                   int2.formula = ~ bribe:copartisan,
                   data=lapop, pair.id = lapop$id, diff=TRUE,
                   cluster = lapop$id, nway = 2)

# conditional effects for plotting
fit.ce <- ConditionalEffect(fit,treat.fac="bribe",cond.fac="copartisan",base.ind = 4)
write.csv(fit.ce,file="replication/ei.csv")
